//
// Created by xuwj on 2021/11/10.
//

#ifndef CV_ASSISTANT_COMMON_XU_H
#define CV_ASSISTANT_COMMON_XU_H

#include "iostream"
#include "string"

#include "pcl/point_types.h"
#include "pcl/io/pcd_io.h"

using namespace std;

/**
 * r,g,b转为h,s,v
 * @param r
 * @param g
 * @param b
 * @return 顺序为H,S,V
 */
//Eigen::Vector3i RGBtoHSV(int r_, int g_, int b_){
//
//    double r = (double)r_ / 255.0;
//    double g = (double)g_ / 255.0;
//    double b = (double)b_ / 255.0;
//
//    double h,s,v;
//    double vmax = max(r,g,b);
//    double vmin = min(r,g,b);
//
//    if((vmax - vmin) < 1e-4){
//        h = 0.0;
//    }
//    else if(r == vmax){
//        h = (g - b) / (vmax - vmin);
//    }
//    else if(g == vmax){
//        h = 2 + (b - r) / (vmax - vmin);
//    }
//    else if(b == vmax){
//        h = 4 + (r - g) / (vmax - vmin);
//    }
//
//}

Eigen::Vector3d RGBtoHSV(int r, int g, int b){

    double h,s,v;
    int vmax = max(r,max(g,b));
    int vmin = min(r,min(g,b));

    double delta = (double)(vmax - vmin);
    if(delta < 1e-4){
        h = 0.0;
    }
    else if(r == vmax){
        h = (double)(g - b) / delta;
    }
    else if(g == vmax){
        h = 2.0 + (double)(b - r) / delta;
    }
    else if(b == vmax){
        h = 4.0 + (double)(r - g) / delta;
    }

    h = h*60;
    if(h<0)
        h += 360;

    v = (double)vmax / 255.0;
    s = delta / v;

    Eigen::Vector3d res(h,s,v);
    return res;
}



#endif //CV_ASSISTANT_COMMON_XU_H
